<?php echo $header;echo $sidebar ?>		

<link rel="stylesheet" href="<?php echo base_url(); ?>/assets/admin/css/new_font-awesome.css"/>
<link href="<?php echo $this->config->base_url(); ?>assets/admin/css/jquery-ui.css" rel="stylesheet">
	<link href="<?php echo $this->config->base_url(); ?>assets/admin/css/chosen.css" rel="stylesheet">
	<link href="<?php echo $this->config->base_url(); ?>assets/admin/css/chosen-bootstrap.css" rel="stylesheet">
	<script type="text/javascript" src="<?php echo $this->config->base_url(); ?>assets/admin/js/chosen.jquery.js"></script>
	<script type="text/javascript" src="<?php echo $this->config->base_url(); ?>assets/admin/js/jquery-ui.js"></script>
	<script src="<?php echo $this->config->base_url(); ?>assets/admin/media/js/jquery.dataTables.columnFilter.js" type="text/javascript"></script>
	<style>
	select {background-color: #FFFFFF;border: 1px solid #CCCCCC;width: 200px !important;}
	.clear{clear: both;}
	</style>
	<div class="span10 content">

		<?php echo $hugemenu ?>

		<h1>Tickets</h1>

		<?php if($this->session->flashdata('message')) :?>
			<div class="alert alert-success">
				<?php echo $this->session->flashdata('message') ?>
			</div>
		<?php endif; ?>
		
		<?php #if($success_message) { echo "<div class=\"alert alert-success\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $success_message . "</div>"; } ?>
		<?php #if($message) { echo "<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $message . "</div>"; } ?>
		

		<div>
			<?php 
	        $error = $this->session->flashdata('error');
	            	
	        if($error)
	        {
	        	echo "<div class='alert alert-danger'>{$error}</div>";
	        } ?>
	        
			<hr>
			<form class="form-inline visible-lg" role="form" action="<?php echo base_url(); ?>index.php/tickets/filter/" method="get">
				<div class="row">
					<div class="col-lg-12" style="margin-left:15px;">
						<?php
						$critical = null;
						$high = null;
						$medium = null;
						$low = null;
						$color_severity = null;
						
						if(isset($_GET['severity']))
						{
							if($_GET['severity'] == '104')
							{
								$critical = "selected='selected'";
								$color_severity = "style='border:1px solid #0088cc;color:#000;margin-right:4px;'";
							}
							elseif($_GET['severity'] == '105')
							{
								$high = "selected='selected'";
								$color_severity = "style='border:1px solid #0088cc;color:#000;margin-right:4px;'";
							}
							elseif($_GET['severity'] == '106')
							{
								$medium = "selected='selected'";
								$color_severity = "style='border:1px solid #0088cc;color:#000;margin-right:4px;'";
							}
							elseif($_GET['severity'] == '107')
							{
								$low = "selected='selected'";
								$color_severity = "style='border:1px solid #0088cc;color:#000;margin-right:4px;'";
							}
							else
							{
								$color_severity = "style='margin-right:4px;'";
							}
						} 
						else 
						{
							$color_severity = "style='margin-right:4px;'";
						} ?>
						
						<select name="severity" class="form-control input-sm col-lg-1" <?php echo $color_severity; ?>>
						  	<option value="">Filter Severity</option>
					      	<option <?php echo $critical; ?> value="104">Critical</option>
					      	<option <?php echo $high; ?> value="105">High</option>
					      	<option <?php echo $medium; ?> value="106">Medium</option>
					      	<option <?php echo $low; ?> value="107">Low</option>
						</select>
					
						<?php
		        		$open = null;
						$development = null;
						$testing = null;
						$closed = null;
						$hold = null;
						$color_status = null;
						
						if(isset($_GET['status']))
						{
							
							if($_GET['status'] == '100')
							{
								$open = "selected='selected'";
								$color_status = "style='border:1px solid #0088cc;color:#000;margin-right:4px;'";
							}
							elseif($_GET['status'] == '101')
							{
								$development = "selected='selected'";
								$color_status = "style='border:1px solid #0088cc;color:#000;margin-right:4px;'";
							}
							elseif($_GET['status'] == '102')
							{
								$testing = "selected='selected'";
								$color_status = "style='border:1px solid #0088cc;color:#000;margin-right:4px;'";
							}
							elseif($_GET['status'] == '103')
							{
								$closed = "selected='selected'";
								$color_status = "style='border:1px solid #0088cc;color:#000;margin-right:4px;'";
							}
							elseif($_GET['status'] == '108')
							{
								$hold = "selected='selected'";
								$color_status = "style='border:1px solid #0088cc;color:#000;margin-right:4px;'";
							} 
							else
							{
								$color_status = "style='margin-right:4px;'";
							}
						} 
						else
						{
							$color_status = "style='margin-right:4px;'";
						} ?>
						
						<select name="status" class="form-control input-sm col-lg-1" <?php echo $color_status; ?>>
						  	<option value="">Filter Status</option>
					      	<option <?php echo $open; ?> value="100">Open</option>
					      	<option <?php echo $development; ?> value="101">Development</option>
					      	<option <?php echo $testing; ?> value="102">Testing</option>
					      	<option <?php echo $hold; ?> value="108">On Hold</option>
					      	<option <?php echo $closed; ?> value="103">Closed</option>
						</select>
					
						<?php
		        		$color_department = null;
		        		
		        		if(isset($_GET['department']))
		        		{
		        			$found = false;
		        			
							for($i = 0; $i < count($departments); ++$i)
							{ 
								if($departments[$i]['department_id'] == $_GET['department'])
								{ 
									$found = true;
									$color_department = "style='border:1px solid #0088cc;color:#000;margin-right:4px;'";
								} 
							} 
							
							if(!$found)
								$color_department = "style='margin-right:4px;'";
						} 
						else
						{
							$color_department = "style='margin-right:4px;'";
						} ?>
						
						<select name="department" class="form-control input-sm col-lg-1" <?php echo $color_department; ?>>
			        		<option value="">Filter Department</option>
					      	<?php
							for($i = 0; $i < count($departments); ++$i)
							{ 
								if($departments[$i]['department_id'] == $_GET['department'])
								{ ?>
									<option value="<?php echo $departments[$i]['department_id']; ?>" selected="selected"><?php echo $departments[$i]['department_name']; ?></option>
								<?php
								}
								else
								{ ?>
									<option value="<?php echo $departments[$i]['department_id']; ?>"><?php echo $departments[$i]['department_name']; ?></option>
								<?php
								}
							} ?>
				      	</select>
					
						<?php
		        		$color_project = null;
		        		
		        		if(isset($_GET['project']))
		        		{
		        			$found = false;
		        			
							for($i = 0; $i < count($projects); ++$i)
							{ 
								if($projects[$i]['project_id'] == $_GET['project'])
								{ 
									$found = true;
									$color_project = "style='border:1px solid #0088cc;color:#000;margin-right:4px;'";
								} 
							} 
							
							if(!$found)
								$color_project = "style='margin-right:4px;'";
						} 
						else
						{
							$color_project = "style='margin-right:4px;'";
						} ?>
						
			        	<select name="project" class="form-control input-sm col-lg-1" <?php echo $color_project; ?>>
			        		<option value="">Filter Project</option>
					      	<?php
							for($i = 0; $i < count($projects); ++$i)
							{ 
								if($projects[$i]['project_id'] == $_GET['project'])
								{ ?>
									<option value="<?php echo $projects[$i]['project_id']; ?>" selected="selected"><?php echo $projects[$i]['project_name']; ?></option>
								<?php
								}
								else
								{ ?>
									<option value="<?php echo $projects[$i]['project_id']; ?>"><?php echo $projects[$i]['project_name']; ?></option>
								<?php
								}
							} ?>
				      	</select>
					
						<?php
		        		$color_processes = null;
		        		
		        		if(isset($_GET['process']))
		        		{
		        			$found = false;
		        			
							for($i = 0; $i < count($processes); ++$i)
							{ 
								if($processes[$i]['process_id'] == $_GET['process'])
								{
									$found = true;
									$color_processes = "style='border:1px solid #0088cc;color:#000;margin-right:4px;'";
								} 
							} 
							
							if(!$found)
								$color_processes = "style='margin-right:4px;'";
						} 
						else
						{
							$color_processes = "style='margin-right:4px;'";
						} ?>
						
			        	<select name="process" class="form-control input-sm col-lg-1" <?php echo $color_processes; ?>>
			        		<option value="">Filter Process</option>
					      	<?php
							for($i = 0; $i < count($processes); ++$i)
							{ 
								if($processes[$i]['process_id'] == $_GET['process'])
								{ ?>
									<option value="<?php echo $processes[$i]['process_id']; ?>" selected="selected"><?php echo $processes[$i]['process_name']; ?></option>
								<?php
								}
								else
								{ ?>
									<option value="<?php echo $processes[$i]['process_id']; ?>"><?php echo $processes[$i]['process_name']; ?></option>
								<?php
								}
							} ?>
				      	</select>
					
						<?php
		        		$color_users = null;
		        		
		        		if(isset($_GET['user']))
		        		{
							for($i = 0; $i < count($users); ++$i)
							{ 
								if($users[$i]['user_id'] == $_GET['user'])
								{ 
									$color_users = "style='border:1px solid #0088cc;color:#000;'";
								} 
							} 
						} ?>
						
			        	<select name="user" class="form-control input-sm col-lg-1" <?php echo $color_users; ?>>
			        		<option value="">Filter User</option>
					      	<?php
							for($i = 0; $i < count($users); ++$i)
							{ 
								if($users[$i]['user_id'] == $_GET['user'])
								{ ?>
									<option value="<?php echo $users[$i]['user_id']; ?>" selected="selected"><?php echo $users[$i]['user_first_name'].' '.$users[$i]['user_last_name']; ?></option>
								<?php
								}
								else
								{ ?>
									<option value="<?php echo $users[$i]['user_id']; ?>"><?php echo $users[$i]['user_first_name'].' '.$users[$i]['user_last_name']; ?></option>
								<?php
								}
							} ?>
				      	</select>
					
						<button type="submit" class="btn btn-primary btn-sm pull-right">Filter</button>
					</div>
				</div>
			</form>
			
			<div style="margin-top: 20px;">
				<a href="<?php echo base_url(); ?>index.php/tickets/create"><button type="button" class="btn btn-primary pull-left">New</button></a>
			</div>
			<div class="clear"></div>
			<hr>
			
			
			<?php  
			if($tickets)
			{ ?>
				<table class="table table-striped table-bordered table-hover datatables">
					<thead>
						<tr>
							<th>Title</th>
							<th>Due</th>
							<th class="hidden-xs">Severity</th>
							<th class="hidden-xs">Status</th>
						</tr>
					</thead>
					<tbody>
						<?php 
				  		for($i = 0; $i < count($tickets); ++$i)
				  		{ ?>
							<tr>
								<td><a href="<?php echo base_url(); ?>index.php/tickets/view/<?php echo $tickets[$i]['tickets_id']; ?>"><?php echo $tickets[$i]['tickets_title']; ?></a></td>
								<td><?php echo date('m/d/y', strtotime($tickets[$i]['tickets_desired_completion'])); ?></td>
								<td class="hidden-xs">
						      		<?php 
						      		$severity = $tickets[$i]['tickets_severity_description'];
						      		
						      		if($severity == 'Critical')
						      		{
						      			echo "<span class='label label-danger'>{$severity}<span>";
						      		}
						      		elseif($severity == 'High')
						      		{
						      			echo "<span class='label label-warning'>{$severity}<span>";
						      		}
						      		elseif($severity == 'Medium')
						      		{
						      			echo "<span class='label label-info'>{$severity}<span>";
						      		}
						      		elseif($severity == 'Low')
						      		{
						      			echo "<span class='label label-success'>{$severity}<span>";
						      		} ?>
						      	</td>
						      	<td class="hidden-xs">
						      		<?php 
						      		$status = $tickets[$i]['tickets_status_description'];
						      		
						      		if($status == 'Closed')
						      		{
						      			echo "<span class='label label-danger'>{$status}<span>";
						      		}
						      		else
						      		{
						      			echo "<span class='label label-success'>{$status}<span>";
						      		} ?>
						      	</td>
							</tr>
						<?php 
				  		} ?>
					</tbody>
				</table>
			<?php 
			} 
			else
			{ ?>
				<p>Your company does not have any open tickets at the moment.</p>
			<?php 
			} ?>
    	</div>
		
		
	</div><!--/content-->
	
	<script src="<?php echo $this->config->base_url(); ?>assets/admin/js/jquery-ui-1.10.2.custom.min.js"></script> <!-- jQuery UI -->
	<script src="<?php echo $this->config->base_url(); ?>assets/admin/js/sparklines.js"></script>
	<script src="<?php echo $this->config->base_url(); ?>assets/admin/js/fullcalendar.min.js"></script> <!-- Full Google Calendar - Calendar -->
	<script src="<?php echo $this->config->base_url(); ?>assets/admin/js/bootstrap-datetimepicker.min.js"></script> <!-- Date picker -->
	<script src="<?php echo $this->config->base_url(); ?>assets/admin/js/DT_bootstrap.js"></script> <!-- jQuery UI -->
	<script src="<?php echo $this->config->base_url(); ?>assets/admin/js/jquery.prettyPhoto.js"></script> <!-- prettyPhoto -->
<?php echo $footer ?>